package com.ebpm.designer.menu
{
	import com.ebpm.designer.NodeContainer;
	import com.ebpm.designer.WF;
	
	import flash.display.BitmapData;
	import flash.events.MouseEvent;
	import flash.geom.Matrix;
	import flash.net.FileReference;
	import flash.utils.ByteArray;
	
	import mx.controls.Alert;
	import mx.graphics.codec.JPEGEncoder;
	
	/**
	 * 截图菜单
	 **/
	public class ImageCutMenu extends MenuItem
	{
		public function ImageCutMenu(iconImage:Class, x:Number=0, y:Number=0)
		{
			super(iconImage, x, y);
		}
		
		override public function _click(event:MouseEvent):void
		{
			if(WF.wp.nodeContainers == null || WF.wp.nodeContainers.length == 0) {
				Alert.show("请绘图以后再截图!");
				return ;
			}
			var maxX:Number = 0;
			var maxY:Number = 0;
			for(var i:Number=0; i<WF.wp.nodeContainers.length; i++) {
				var n:NodeContainer = WF.wp.nodeContainers.getItemAt(i) as NodeContainer;
				var x:Number = n.x + n.width;
				var y:Number = n.y + n.height;
				if(x > maxX) maxX = x;
				if(y > maxY) maxY = y;
			}
			
			var bitmapData:BitmapData = new BitmapData(maxX + 50, maxY + 50);
			WF.wp.menu.setVisible(false);
			WF.wp.hideVariablePanels();
			//this表示给整个Application快照 ，你也可以换成pic，给图片的容器拍照，得到的是图片的照片保存。
			bitmapData.draw(WF.wp,new Matrix());
			var file:FileReference = new FileReference();
			var jpg:JPEGEncoder = new JPEGEncoder();
			var ba:ByteArray = jpg.encode(bitmapData);
			file.save(ba,"pic.jpg");
			WF.wp.menu.setVisible(true);
		}
		
		override public function getIconImage() : Class {
			return WF.MenuImageCut;
		}
		
		override public function getIconImageOver() :Class {
			return WF.MenuImageCut1;
		}
		
		
		
		
		
		
		
		
		
		
		
		
	}
}